package com.system.brandsserver.service.impl;

import com.system.brandsserver.mapper.BrandMapper;
import com.system.brandsserver.service.BrandService;
import com.system.commonutils.bean.ApiResult;
import com.system.commonutils.pojo.GoodsBrand;

import com.system.commonutils.pojo.GoodsType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ll
 * Date: 2020/07/07 10:33
 * Description:
 * Version: V1.0
 */
@Service
public class BrandServiceImpl implements BrandService {

    @Autowired
    BrandMapper brandMapper;

    @Autowired(required = false)
    private GoodsBrand goodsBrand;

//获取当前时间
    String year =new SimpleDateFormat("yyyy").format(Calendar.getInstance().getTime());
    String month =new SimpleDateFormat("MM").format(Calendar.getInstance().getTime());
    String day=new SimpleDateFormat("dd").format(Calendar.getInstance().getTime());
    String hh=new SimpleDateFormat("HH").format(Calendar.getInstance().getTime());
    String fen = new SimpleDateFormat("mm").format(Calendar.getInstance().getTime());
    String second=new SimpleDateFormat("ss").format(Calendar.getInstance().getTime());

    @Override
    public List<GoodsBrand> queryBrand(GoodsBrand goodsBrand) {
        long goodsBrand_id = goodsBrand.getGoodsBrand_id();
        System.out.println("商品类型id:" + goodsBrand_id);

        String goodsBrand_name = goodsBrand.getGoodsBrand_name();
        System.out.println("商品类型名称:" + goodsBrand_name);
        int currentPage = (goodsBrand.getNowsPage()-1) * goodsBrand.getPageSize();
        System.out.println("当前页码:" + currentPage);
        goodsBrand.setNowsPage(currentPage);
        List<GoodsBrand> list = brandMapper.queryBrand(goodsBrand);
        System.out.println(list);
        return list;
    }

    /**
     * @param goodsBrand
     * @return
     */
    @Override
    public int queryTotalSize(GoodsBrand goodsBrand) {
        this.goodsBrand = goodsBrand;
        int totalSize = brandMapper.querytotalSize(goodsBrand);
        return totalSize;
    }

    @Override
    public  List<GoodsBrand> selectBrand(GoodsBrand goodsBrand) {
        List<GoodsBrand> list=  brandMapper.selectBrand(goodsBrand);
        System.out.println("=========" + list);
        return list;

    }

    @Override
    public int delBrand(GoodsBrand goodsBrand) {
        int result = brandMapper.delBrand(goodsBrand);
        return result;
    }


    @Override
    public List<GoodsBrand> isExist(String getGoodsBrand_name) {
        List<GoodsBrand> list = brandMapper.isExist(getGoodsBrand_name);
        return list;
    }

    @Override
    public int addBrand(GoodsBrand goodsBrand) {
//        String time = year +("-")+ month+("-")+day+("-")+ hh+(":")+fen+(":")+second;
//        Date date =
//        goodsBrand.setCreatetime(time);
        int result = brandMapper.addBrand(goodsBrand);
        return result;
    }

    @Override
    public int editBrand(GoodsBrand goodsBrand) {
        System.out.println("goodsTypeId===" + goodsBrand.getGoodsBrand_id() + "===goodsTypeName===" + goodsBrand.getGoodsBrand_name() );
        List<GoodsType> list = brandMapper.isExistBesidesMe(goodsBrand);
        if(list.size() > 0){
            return 0;
        }else{
            int result = brandMapper.editBrand(goodsBrand);
            System.out.println("result ==== " + result);
            return result;
        }
    }

//    @Override
//    public List<GoodsBrand> selectBrand(GoodsBrand goodsBrand)
//    {
//        return brandMapper.selectBrand(goodsBrand);
//    }
}

